package com.sxfq.loansupermarket.backsystem.modular.doctorLooked.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.constant.factory.PageFactory;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.common.exception.BizExceptionEnum;
import com.sxfq.loansupermarket.backsystem.common.exception.BussinessException;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.support.DateTimeKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.core.util.ToolUtil;
import com.sxfq.loansupermarket.backsystem.modular.arrival.service.ICustomerService;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.DoctorInfo;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.entity.*;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.service.IDoctorLookedService;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.entity.ConsultantInfo;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.service.IConsultantService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 医生回访
 *
 * @author py
 * @Date 2018年4月19日23:15:54
 */
@Controller
@RequestMapping("/doctorRevisit")
public class DoctorRevisitController extends BaseController {
    @Autowired
    IDoctorLookedService service;

    @Autowired
    IConsultantService consultantService;

    @Autowired
    ICustomerService customerService;

    @Autowired
    private SqlMapper sqlMapper;

    private String PREFIX = "/doctorLooked/";

    /**
     * 跳转到医生看诊 传客户ID 和预约ID 和回访时间
     */
    @RequestMapping(value = "/doctor_follow/{ids}")
    public String consultant(@PathVariable String ids,Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String id = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String customerId = ids.split(",")[2];
        String revisitTime = ids.split(",")[3];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(revisitTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber,t2.doctor as doctor," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc,t2.one_channel as oneChannel,left(t1.first_visit_date,19) as firstVisitDate" +
                " from " + ShiroKit.getUser().getCustomer_info() + " t2 left join reservations_info t1 on t1.id = t2.reservations_id where t2.id='" + customerId + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String sql2 = "select r.id,r.reservations_id,r.customer_id,r.revisit,left(r.revisit_time,10) as revisitTime,r.outpatient_name," +
                " r.revisit_content,r.doctor,r.revisit_status,r.remarks  from return_doctor_visit_info r " +
                " where  r.revisit_time ='"+ revisitTime +"' and id='"+id+"' limit 1";
        DoctorRevisitInfo doctorRevisitInfo = sqlMapper.selectOne(sql2, DoctorRevisitInfo.class);
        //随访记录
        String sql4 = "select r.id,r.reservations_id,r.customer_id,r.revisit,r.create_name,r.revisit_time,r.outpatient_name,r.revisit_content,r.doctor,r.revisit_status,r.remarks from return_doctor_visit_info r where r.customer_id ='"+customerId+"' ";
        List<DoctorRevisitInfo> doctorRevisitInfoList = sqlMapper.selectList(sql4, DoctorRevisitInfo.class);
        for (DoctorRevisitInfo info1 : doctorRevisitInfoList) {
            if (info1.getRevisitTime() != "" && info1.getRevisitTime() != null) {
                info1.setRevisitTime(info1.getRevisitTime().substring(0,11));
            }
        }
        //病历记录
        String sql5 = "select left(t.create_appointment_time,19) as createAppointmentTime,left(t.start_time,19) as startTime,left(t.arrival_time,19) as arrivalTime,t.id as id," +
                "t.reservations_id as reservationsId,t.doctor as doctor,t.field_tc as fieldTc,t.remarks as remarks,t.remarks_reservation as remarksReservation," +
                "t.arrival_status as arrivalStatus," +
                "t.archiving as archiving,t.arrival_store as arrivalStore,t.customer_status as customerStatus,t.status as status,t.appointment_pay_service as appointmentPayService," +
                "t1.zhushu as zhushu,t1.remarkss as remarkss,t1.doctor_advice as doctorAdvice from " + ShiroKit.getUser().getCustomer_info() + " t " +
                "left join case_info t1 on t.id=t1.customer_id where t.reservations_id='" + reservationsId + "' " +
                " and t.arrival_status in (1,2,3,4,5,6,9,10) and t1.arrival_store='"+ShiroKit.getUser().getOutpatientName()+"' " +
                " order by start_time desc";
        List<DoctorDiagnosisInfo> DoctorDiagnosisInfoList = sqlMapper.selectList(sql5, DoctorDiagnosisInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList = sqlMapper.selectList(doctorListSql, DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("doctorRevisitInfoList", doctorRevisitInfoList);  //随访记录
        model.addAttribute("DoctorDiagnosisInfoList", DoctorDiagnosisInfoList); //就诊记录
        model.addAttribute("doctorRevisitInfo", doctorRevisitInfo);
        model.addAttribute("customerId", customerId);
        model.addAttribute("createName",ShiroKit.getUser().getAccount());  //创建人
        model.addAttribute("arrivalStore", ShiroKit.getUser().getOutpatientName());  //门店
        return PREFIX + "doctor_follow.html";
    }

    @RequestMapping(value = "/look_doctor_follow/{ids}")
    public String lookDoctorFollow(@PathVariable String ids,Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String id = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String customerId = ids.split(",")[2];
        String revisitTime = ids.split(",")[3];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(revisitTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber,t2.doctor as doctor," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc,t2.one_channel as oneChannel,left(t1.first_visit_date,19) as firstVisitDate" +
                " from " + ShiroKit.getUser().getCustomer_info() + " t2 left join reservations_info t1 on t1.id = t2.reservations_id where t2.id='" + customerId + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String sql2 = "select r.id,r.reservations_id,r.customer_id,r.revisit,left(r.revisit_time,10) as revisitTime,r.outpatient_name," +
                " r.revisit_content,r.doctor,r.revisit_status,r.remarks  from return_doctor_visit_info r " +
                " where  r.revisit_time ='"+ revisitTime +"' and id='"+id+"' limit 1";
        DoctorRevisitInfo doctorRevisitInfo = sqlMapper.selectOne(sql2, DoctorRevisitInfo.class);
        //随访记录
        String sql4 = "select r.id,r.reservations_id,r.customer_id,r.revisit,r.create_name,r.revisit_time,r.outpatient_name,r.revisit_content,r.doctor,r.revisit_status,r.remarks from return_doctor_visit_info r where r.customer_id ='"+customerId+"' ";
        List<DoctorRevisitInfo> doctorRevisitInfoList = sqlMapper.selectList(sql4, DoctorRevisitInfo.class);
        for (DoctorRevisitInfo info1 : doctorRevisitInfoList) {
            if (info1.getRevisitTime() != "" && info1.getRevisitTime() != null) {
                info1.setRevisitTime(info1.getRevisitTime().substring(0,11));
            }
        }
        //病历记录
        String sql5 = "select left(t.create_appointment_time,19) as createAppointmentTime,left(t.start_time,19) as startTime,left(t.arrival_time,19) as arrivalTime,t.id as id," +
                "t.reservations_id as reservationsId,t.doctor as doctor,t.field_tc as fieldTc,t.remarks as remarks,t.remarks_reservation as remarksReservation," +
                "t.arrival_status as arrivalStatus," +
                "t.archiving as archiving,t.arrival_store as arrivalStore,t.customer_status as customerStatus,t.status as status,t.appointment_pay_service as appointmentPayService," +
                "t1.zhushu as zhushu,t1.remarkss as remarkss,t1.doctor_advice as doctorAdvice from " + ShiroKit.getUser().getCustomer_info() + " t " +
                "left join case_info t1 on t.id=t1.customer_id where t.reservations_id='" + reservationsId + "' " +
                " and t.arrival_status in (1,2,3,4,5,6,9,10) and t1.arrival_store='"+ShiroKit.getUser().getOutpatientName()+"' " +
                " order by start_time desc";
        List<DoctorDiagnosisInfo> DoctorDiagnosisInfoList = sqlMapper.selectList(sql5, DoctorDiagnosisInfo.class);
        if (ShiroKit.getSessionAttr("doctorList") == null) {
            String getListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + tableHead + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            ShiroKit.setSessionAttr("doctorList", sqlMapper.selectList(getListSql));
        }
        model.addAttribute("doctorList",  ShiroKit.getSessionAttr("doctorList"));
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("doctorRevisitInfoList", doctorRevisitInfoList);  //随访记录
        model.addAttribute("DoctorDiagnosisInfoList", DoctorDiagnosisInfoList); //就诊记录
        model.addAttribute("doctorRevisitInfo", doctorRevisitInfo);
        model.addAttribute("customerId", customerId);
        model.addAttribute("createName",ShiroKit.getUser().getAccount());  //创建人
        model.addAttribute("arrivalStore", ShiroKit.getUser().getOutpatientName());  //门店
        return PREFIX + "look_doctor_follow.html";
    }

    @RequestMapping(value = "/look_doctor_follows/{ids}")
    public String lookDoctorFollows(@PathVariable String ids,Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String id = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String customerId = ids.split(",")[2];
        String revisitTime = ids.split(",")[3];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(revisitTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber,t2.doctor as doctor," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc,t2.one_channel as oneChannel,left(t1.first_visit_date,19) as firstVisitDate" +
                " from " + ShiroKit.getUser().getCustomer_info() + " t2 left join reservations_info t1 on t1.id = t2.reservations_id where t2.id='" + customerId + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String sql2 = "select r.id,r.reservations_id,r.customer_id,r.revisit,left(r.revisit_time,10) as revisitTime,r.outpatient_name," +
                " r.revisit_content,r.doctor,r.revisit_status,r.remarks  from return_doctor_visit_info r " +
                " where  r.revisit_time ='"+ revisitTime +"' and id='"+id+"' limit 1";
        DoctorRevisitInfo doctorRevisitInfo = sqlMapper.selectOne(sql2, DoctorRevisitInfo.class);
        //随访记录
        String sql4 = "select r.id,r.reservations_id,r.customer_id,r.revisit,r.create_name,r.revisit_time,r.outpatient_name,r.revisit_content,r.doctor,r.revisit_status,r.remarks from return_doctor_visit_info r where r.customer_id ='"+customerId+"' ";
        List<DoctorRevisitInfo> doctorRevisitInfoList = sqlMapper.selectList(sql4, DoctorRevisitInfo.class);
        for (DoctorRevisitInfo info1 : doctorRevisitInfoList) {
            if (info1.getRevisitTime() != "" && info1.getRevisitTime() != null) {
                info1.setRevisitTime(info1.getRevisitTime().substring(0,11));
            }
        }
        //病历记录
        String sql5 = "select left(t.create_appointment_time,19) as createAppointmentTime,left(t.start_time,19) as startTime,left(t.arrival_time,19) as arrivalTime,t.id as id," +
                "t.reservations_id as reservationsId,t.doctor as doctor,t.field_tc as fieldTc,t.remarks as remarks,t.remarks_reservation as remarksReservation," +
                "t.arrival_status as arrivalStatus," +
                "t.archiving as archiving,t.arrival_store as arrivalStore,t.customer_status as customerStatus,t.status as status,t.appointment_pay_service as appointmentPayService," +
                "t1.zhushu as zhushu,t1.remarkss as remarkss,t1.doctor_advice as doctorAdvice from " + ShiroKit.getUser().getCustomer_info() + " t " +
                "left join case_info t1 on t.id=t1.customer_id where t.reservations_id='" + reservationsId + "' " +
                " and t.arrival_status in (1,2,3,4,5,6,9,10) and t1.arrival_store='"+ShiroKit.getUser().getOutpatientName()+"' " +
                " order by start_time desc";
        List<DoctorDiagnosisInfo> DoctorDiagnosisInfoList = sqlMapper.selectList(sql5, DoctorDiagnosisInfo.class);
        if (ShiroKit.getSessionAttr("doctorList") == null) {
            String getListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + tableHead + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            ShiroKit.setSessionAttr("doctorList", sqlMapper.selectList(getListSql));
        }
        model.addAttribute("doctorList",  ShiroKit.getSessionAttr("doctorList"));
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("doctorRevisitInfoList", doctorRevisitInfoList);  //随访记录
        model.addAttribute("DoctorDiagnosisInfoList", DoctorDiagnosisInfoList); //就诊记录
        model.addAttribute("doctorRevisitInfo", doctorRevisitInfo);
        model.addAttribute("customerId", customerId);
        model.addAttribute("createName",ShiroKit.getUser().getAccount());  //创建人
        model.addAttribute("arrivalStore", ShiroKit.getUser().getOutpatientName());  //门店
        return PREFIX + "lookDoctorFollows.html";
    }

    @RequestMapping(value = "/look_doctor_followsd/{ids}")
    public String look_doctor_followsd(@PathVariable String ids,Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String id = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String customerId = ids.split(",")[2];
        String revisitTime = ids.split(",")[3];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(revisitTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber,t2.doctor as doctor," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc,t2.one_channel as oneChannel,left(t1.first_visit_date,19) as firstVisitDate" +
                " from " + ShiroKit.getUser().getCustomer_info() + " t2 left join reservations_info t1 on t1.id = t2.reservations_id where t2.id='" + customerId + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String sql2 = "select r.id,r.reservations_id,r.customer_id,r.revisit,left(r.revisit_time,10) as revisitTime,r.outpatient_name," +
                " r.revisit_content,r.doctor,r.revisit_status,r.remarks  from return_doctor_visit_info r " +
                " where  r.revisit_time ='"+ revisitTime +"' and id='"+id+"' limit 1";
        DoctorRevisitInfo doctorRevisitInfo = sqlMapper.selectOne(sql2, DoctorRevisitInfo.class);
        //随访记录
        String sql4 = "select r.id,r.reservations_id,r.customer_id,r.revisit,r.create_name,r.revisit_time,r.outpatient_name,r.revisit_content,r.doctor,r.revisit_status,r.remarks from return_doctor_visit_info r where r.customer_id ='"+customerId+"' ";
        List<DoctorRevisitInfo> doctorRevisitInfoList = sqlMapper.selectList(sql4, DoctorRevisitInfo.class);
        for (DoctorRevisitInfo info1 : doctorRevisitInfoList) {
            if (info1.getRevisitTime() != "" && info1.getRevisitTime() != null) {
                info1.setRevisitTime(info1.getRevisitTime().substring(0,11));
            }
        }
        //病历记录
        String sql5 = "select left(t.create_appointment_time,19) as createAppointmentTime,left(t.start_time,19) as startTime,left(t.arrival_time,19) as arrivalTime,t.id as id," +
                "t.reservations_id as reservationsId,t.doctor as doctor,t.field_tc as fieldTc,t.remarks as remarks,t.remarks_reservation as remarksReservation," +
                "t.arrival_status as arrivalStatus," +
                "t.archiving as archiving,t.arrival_store as arrivalStore,t.customer_status as customerStatus,t.status as status,t.appointment_pay_service as appointmentPayService," +
                "t1.zhushu as zhushu,t1.remarkss as remarkss,t1.doctor_advice as doctorAdvice from " + ShiroKit.getUser().getCustomer_info() + " t " +
                "left join case_info t1 on t.id=t1.customer_id where t.reservations_id='" + reservationsId + "' " +
                " and t.arrival_status in (1,2,3,4,5,6,9,10) and t1.arrival_store='"+ShiroKit.getUser().getOutpatientName()+"' " +
                " order by start_time desc";
        List<DoctorDiagnosisInfo> DoctorDiagnosisInfoList = sqlMapper.selectList(sql5, DoctorDiagnosisInfo.class);
        if (ShiroKit.getSessionAttr("doctorList") == null) {
            String getListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + tableHead + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            ShiroKit.setSessionAttr("doctorList", sqlMapper.selectList(getListSql));
        }
        model.addAttribute("doctorList",  ShiroKit.getSessionAttr("doctorList"));
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("doctorRevisitInfoList", doctorRevisitInfoList);  //随访记录
        model.addAttribute("DoctorDiagnosisInfoList", DoctorDiagnosisInfoList); //就诊记录
        model.addAttribute("doctorRevisitInfo", doctorRevisitInfo);
        model.addAttribute("customerId", customerId);
        model.addAttribute("createName",ShiroKit.getUser().getAccount());  //创建人
        model.addAttribute("arrivalStore", ShiroKit.getUser().getOutpatientName());  //门店
        return PREFIX + "ldoctorFollowsd.html";
    }

    /**
     * 跳转到医生再随访
     */
    @RequestMapping("/doctor_followUp2")
    public String doctor_followUp(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_followUp2.html";
    }

    /**
     * 跳转到医生再随访
     */
    @RequestMapping("/lookedDoctorFollowUp2")
    public String lookedDoctorFollowUp2(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "lookedDoctorFollowUp2.html";
    }

    /**
     * 表格中 修改  保存在随访
     */
    @RequestMapping(value = "/addDoctorContent", method = RequestMethod.POST)
    @ResponseBody
    public int addDoctorContents(String customerId, String doctor, String revisitTime,
                                 String remarks, String reservationsId, String arrivalStore, String createName,String revisit) {
        int revisitStatus = 1;
        String sql = "insert into return_doctor_visit_info (reservations_id,customer_id,revisit,revisit_time," +
                "outpatient_name,doctor,remarks,create_name,revisit_status,create_time) values ('" + reservationsId
                + "','" + customerId + "','" + revisit + "','" + revisitTime + "','" + ShiroKit.getUser().getOutpatientName()
                + "','" + doctor + "','" + remarks + "','" + createName + "','" + revisitStatus + "','"+ DateTimeKit.now()+"')";
        sqlMapper.insert(sql);
        String insertInto = "update " + ShiroKit.getUser().getCustomer_info() + " a set a.visit_status='1' where id='" + customerId + "'";
        return sqlMapper.update(insertInto);
    }

    /**
     * 医生今日随访列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object doctorInfoList(SearchDoctorLookedInfo info, HttpServletRequest request) {
        Page<DoctorLookedInfo> page = new PageFactory<DoctorLookedInfo>().defaultPage();
        if(info.getAbbreviation()=="" || info.getAbbreviation() == null || info.getAbbreviation() =="null" ){
            return  null;
        }else{
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<DoctorLookedInfo> list = service.selectPageListByDoctorRevisit(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = service.selectPageListByDoctorRevisit(page, info);
                }
                page.setTotal(service.getQueryPagesRevisitCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }

    /**
     * 统计查询
     */
    @RequestMapping(value = "/total", method = RequestMethod.GET)
    @ResponseBody
    public List<DoctorLookedInfo> change(String reach,String revisitStatus,String startRevisitTime,String endRevisitTime,String revisit,String createName,String startCreateTime,String endCreateTime) throws Exception {
        String contitionInfo = "";
        contitionInfo +="and t.outpatient_name = '"+ShiroKit.getUser().getOutpatientName()+"'";
        if (StringUtils.isNotBlank(startRevisitTime)) {
            contitionInfo += " and t.revisit_time >='"+startRevisitTime+"' ";
        }
        if (StringUtils.isNotBlank(endRevisitTime)) {
            contitionInfo += " and t.revisit_time <='"+endRevisitTime+"' ";
        }
        if (StringUtils.isNotBlank(startCreateTime)) {
            contitionInfo += " and t.create_time >='"+startCreateTime+"' ";
        }
        if (StringUtils.isNotBlank(endCreateTime)) {
            contitionInfo += " and t.create_time <='"+endCreateTime+"' ";
        }
        if (StringUtils.isNotBlank(revisit)) {
            contitionInfo += " and t.revisit='" + revisit + "' ";
        }
        if (StringUtils.isNotBlank(createName)) {
            contitionInfo += " and t.create_name='" + createName + "' ";
        }
        if (StringUtils.isNotBlank(reach)) {
            contitionInfo += "   and (t1.customer_name like CONCAT('%','"+reach+"','%') or t1.customer_phone like CONCAT('%','"+reach+"','%') or " +
                    "            t1.wechat_number like CONCAT('%','"+reach+"','%') or t1.medical_record_number like CONCAT('%','"+reach+"','%') " +
                    "            or t1.customer_phone2 like CONCAT('%','"+reach+"','%')  or t1.szm like CONCAT('%','"+reach+"','%') or t.doctor like CONCAT('%','"+reach+"','%')) ";
        }
        contitionInfo += " group by t.id";
        String sql = "select count(*) as countNum from (select t.id from return_doctor_visit_info t,"+ShiroKit.getUser().getCustomer_info()+" t1 where t.customer_id = t1.id " + contitionInfo+") t "+
                " union all select count(*) as countNum from (select t.id from  return_doctor_visit_info t , "+ShiroKit.getUser().getCustomer_info()+" t1 where t.customer_id = t1.id and t.revisit_status ='1' " + contitionInfo+") t"+

                " union all  select count(*) as countNum from (select t.id from  return_doctor_visit_info t , "+ShiroKit.getUser().getCustomer_info()+" t1 where t.customer_id = t1.id and t.revisit_status ='2' " + contitionInfo+") t"+

                " union all  select count(*) as countNum from (select t.id from  return_doctor_visit_info t , "+ShiroKit.getUser().getCustomer_info()+" t1 where t.customer_id = t1.id and t.revisit_status ='3' " + contitionInfo+") t"+

                " union all  select count(*) as countNum from (select t.id from  return_doctor_visit_info t , "+ShiroKit.getUser().getCustomer_info()+" t1 where t.customer_id = t1.id and t.revisit_status ='4' " + contitionInfo+") t";
        List<DoctorLookedInfo> tongJiInfoList1 = sqlMapper.selectList(sql, DoctorLookedInfo.class);
        return tongJiInfoList1;
    }

    /**
     * 除单个病例信息(删除按钮ajax 组件请求)
     * 删
     *
     * @param id     病例ID
     * @param result
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deleteCaseInfo/{id}")
    @ResponseBody
    public int deleteCaseInfo(@PathVariable String id, BindingResult result) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        //删除病例对应的牙位信息
        String sql1 = "delete from tooth_site where case_id = '" + id + "'";
        sqlMapper.delete(sql1);
        //删除病例表对应ID的病例信息
        String sql = "delete from case_info where id = '" + id + "'";
        return sqlMapper.delete(sql);
    }

}